home *** CD-ROM | disk | FTP | other *** search
- # This file is a Tcl script to test out the "photo" image type and the
- # other procedures in the file tkImgPhoto.c. It is organized in the
- # standard fashion for Tcl tests.
- #
- # Copyright (c) 1994 The Australian National University
- # Copyright (c) 1994 Sun Microsystems, Inc.
- #
- # See the file "license.terms" for information on usage and redistribution
- # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- #
- # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #
- # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- # AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- #
- # Author: Paul Mackerras (paulus@cs.anu.edu.au)
- #
- # @(#) imgPhoto.test 1.9 95/06/21 15:50:04
-
- if {[info procs test] != "test"} {
- source defs
- }
-
- foreach i [winfo children .] {
- destroy $i
- }
- wm geometry . {}
- raise .
-
- eval image delete [image names]
-
- canvas .c
- pack .c
- update
-
- test imgPhoto-1.1 {options for photo images} {
- image create photo p1 -width 79 -height 83
- list [lindex [p1 configure -width] 4] [lindex [p1 configure -height] 4] \
- [image width p1] [image height p1]
- } {79 83 79 83}
- test imgPhoto-1.2 {options for photo images} {
- list [catch {image create photo p1 -file no.such.file} err] \
- [string tolower $err]
- } {1 {couldn't read image file "no.such.file": no such file or directory}}
- test imgPhoto-1.3 {options for photo images} {
- list [catch {image create photo p1 -file \
- $tk_library/demos/images/teapot.ppm \
- -format no.such.format} err] $err
- } {1 {image file format "no.such.format" is unknown}}
- test imgPhoto-1.4 {options for photo images} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- list [image width p1] [image height p1]
- } {256 256}
- test imgPhoto-1.5 {options for photo images} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm \
- -format ppm -width 79 -height 83
- list [image width p1] [image height p1] \
- [lindex [p1 configure -file] 4] [lindex [p1 configure -format] 4]
- } "79 83 [glob $tk_library]/demos/images/teapot.ppm ppm"
- test imgPhoto-1.6 {options for photo images} {
- image create photo p1 -palette 2/2/2 -gamma 2.2
- list [lindex [p1 configure -gamma] 4] [lindex [p1 configure -palette] 4]
- } {2.2 2/2/2}
- test imgPhoto-1.7 {options for photo images} {
- list [catch {image create photo p1 -file README} err] $err
- } {1 {couldn't recognize data in image file "README"}}
- test imgPhoto-1.8 {options for photo images} {
- list [catch {image create photo -blah blah} err] $err
- } {1 {unknown option "-blah"}}
-
- test imgPhoto-2.1 {ImgPhotoCreate procedure} {
- eval image delete [image names]
- catch {image create photo -blah blah}
- image names
- } {}
- test imgPhoto-2.2 {ImgPhotoCreate procedure} {
- eval image delete [image names]
- image create photo image1
- list [info commands image1] [image names] \
- [image width image1] [image height image1]
- } {image1 image1 0 0}
-
- test imgPhoto-3.1 {ImgPhotoConfigureMaster procedure} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- p1 configure -file $tk_library/demos/images/teapot.ppm
- } {}
- test imgPhoto-3.2 {ImgPhotoConfigureMaster procedure} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- list [catch {p1 configure -file bogus} err] [string tolower $err] \
- [image width p1] [image height p1]
- } {1 {couldn't read image file "bogus": no such file or directory} 256 256}
- test imgPhoto-3.3 {ImgPhotoConfigureMaster procedure} {
- image create photo p1
- .c create image 10 10 -image p1 -tags p1.1 -anchor nw
- .c create image 300 10 -image p1 -tags p1.2 -anchor nw
- update
- p1 configure -file $tk_library/demos/images/teapot.ppm
- update
- list [image width p1] [image height p1] [.c bbox p1.1] [.c bbox p1.2]
- } {256 256 {10 10 266 266} {300 10 556 266}}
-
- eval image delete [image names]
- image create photo p1
- .c create image 10 10 -image p1
- update
-
- test imgPhoto-4.1 {ImgPhotoCmd procedure} {
- list [catch {p1} err] $err
- } {1 {wrong # args: should be "p1 option ?arg arg ...?"}}
- test imgPhoto-4.2 {ImgPhotoCmd procedure} {
- list [catch {p1 blah} err] $err
- } {1 {bad option "blah": must be blank, cget, configure, copy, get, put, read, redither, or write}}
- test imgPhoto-4.3 {ImgPhotoCmd procedure: blank option} {
- p1 blank
- list [catch {p1 blank x} err] $err
- } {1 {wrong # args: should be "p1 blank"}}
- test imgPhoto-4.4 {ImgPhotoCmd procedure: cget option} {
- list [catch {p1 cget} msg] $msg
- } {1 {wrong # args: should be "p1 cget option"}}
- test imgPhoto-4.5 {ImgPhotoCmd procedure: cget option} {
- image create photo p2 -width 25 -height 30
- list [p2 cget -width] [p2 cget -height]
- } {25 30}
- test imgPhoto-4.6 {ImgPhotoCmd procedure: configure option} {
- llength [p1 configure]
- } {7}
- test imgPhoto-4.7 {ImgPhotoCmd procedure: configure option} {
- p1 conf -palette 3/4/2
- p1 configure -palette
- } {-palette {} {} {} 3/4/2}
- test imgPhoto-4.8 {ImgPhotoCmd procedure: configure option} {
- list [catch {p1 configure -blah} msg] $msg
- } {1 {unknown option "-blah"}}
- test imgPhoto-4.9 {ImgPhotoCmd procedure: configure option} {
- list [catch {p1 configure -palette {} -gamma} msg] $msg
- } {1 {value for "-gamma" missing}}
- test imgPhoto-4.10 {ImgPhotoCmd procedure: copy option} {
- image create photo p2 -file $tk_library/demos/images/teapot.ppm
- p1 configure -width 0 -height 0 -palette {} -gamma 1
- p1 copy p2
- list [image width p1] [image height p1] [p1 get 100 100]
- } {256 256 {169 117 90}}
- test imgPhoto-4.11 {ImgPhotoCmd procedure: copy option} {
- list [catch {p1 copy} msg] $msg
- } {1 {wrong # args: should be "p1 copy source-image ?-from x1 y1 x2 y2? ?-to x1 y1 x2 y2? ?-zoom x y? ?-subsample x y?"}}
- test imgPhoto-4.12 {ImgPhotoCmd procedure: copy option} {
- list [catch {p1 copy blah} msg] $msg
- } {1 {image "blah" doesn't exist or is not a photo image}}
- test imgPhoto-4.13 {ImgPhotoCmd procedure: copy option} {
- list [catch {p1 copy p2 -blah} msg] $msg
- } {1 {unrecognized option "-blah": must be -from, -shrink, -subsample, -to, or -zoom}}
- test imgPhoto-4.14 {ImgPhotoCmd procedure: copy option} {
- list [catch {p1 copy p2 -from -to} msg] $msg
- } {1 {the "-from" option requires one to four integer values}}
- test imgPhoto-4.15 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2
- p1 copy p2 -from 0 70 60 120 -shrink
- list [image width p1] [image height p1] [p1 get 20 10]
- } {60 50 {215 154 120}}
- test imgPhoto-4.16 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2 -from 60 120 0 70 -to 20 50
- list [image width p1] [image height p1] [p1 get 40 80]
- } {80 100 {19 92 192}}
- test imgPhoto-4.17 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2 -from 0 120 60 70 -to 0 0 100 100
- list [image width p1] [image height p1] [p1 get 80 60]
- } {100 100 {215 154 120}}
- test imgPhoto-4.18 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2 -from 60 70 0 120 -zoom 2
- list [image width p1] [image height p1] [p1 get 100 50]
- } {120 100 {169 99 47}}
- test imgPhoto-4.19 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2 -from 0 70 60 120
- list [image width p1] [image height p1] [p1 get 100 50]
- } {120 100 {169 99 47}}
- test imgPhoto-4.20 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2 -from 20 20 200 180 -subsample 2 -shrink
- list [image width p1] [image height p1] [p1 get 50 30]
- } {90 80 {207 146 112}}
- test imgPhoto-4.21 {ImgPhotoCmd procedure: copy option} {
- p1 copy p2
- set result [list [image width p1] [image height p1]]
- p1 conf -width 49 -height 51
- lappend result [image width p1] [image height p1]
- p1 copy p2
- lappend result [image width p1] [image height p1]
- p1 copy p2 -from 0 0 10 10 -shrink
- lappend result [image width p1] [image height p1]
- p1 conf -width 0
- p1 copy p2 -from 0 0 10 10 -shrink
- lappend result [image width p1] [image height p1]
- p1 conf -height 0
- p1 copy p2 -from 0 0 10 10 -shrink
- lappend result [image width p1] [image height p1]
- } {256 256 49 51 49 51 49 51 10 51 10 10}
- test imgPhoto-4.22 {ImgPhotoCmd procedure: get option} {
- p1 read $tk_library/demos/images/teapot.ppm
- list [p1 get 100 100] [p1 get 150 100] [p1 get 100 150]
- } {{169 117 90} {172 115 84} {35 35 35}}
- test imgPhoto-4.23 {ImgPhotoCmd procedure: get option} {
- list [catch {p1 get 256 0} err] $err
- } {1 {p1 get: coordinates out of range}}
- test imgPhoto-4.24 {ImgPhotoCmd procedure: get option} {
- list [catch {p1 get 0 -1} err] $err
- } {1 {p1 get: coordinates out of range}}
- test imgPhoto-4.25 {ImgPhotoCmd procedure: get option} {
- list [catch {p1 get} err] $err
- } {1 {wrong # args: should be "p1 get x y"}}
- test imgPhoto-4.26 {ImgPhotoCmd procedure: put option} {
- list [catch {p1 put} err] $err
- } {1 {wrong # args: should be "p1 put {{colors...}...} ?-to x1 y1 x2 y2?"}}
- test imgPhoto-4.27 {ImgPhotoCmd procedure: put option} {
- list [catch {p1 put {{white} {white white}}} err] $err
- } {1 {all elements of color list must have the same number of elements}}
- test imgPhoto-4.28 {ImgPhotoCmd procedure: put option} {
- list [catch {p1 put {{blahgle}}} err] $err
- } {1 {can't parse color "blahgle"}}
- test imgPhoto-4.29 {ImgPhotoCmd procedure: put option} {
- p1 put -to 10 10 20 20 {{white}}
- p1 get 19 19
- } {255 255 255}
- test imgPhoto-4.30 {ImgPhotoCmd procedure: read option} {
- list [catch {p1 read} err] $err
- } {1 {wrong # args: should be "p1 read fileName ?-format format-name? ?-from x1 y1 x2 y2? ?-to x y? ?-shrink?"}}
- test imgPhoto-4.31 {ImgPhotoCmd procedure: read option} {
- list [catch {p1 read $tk_library/demos/images/teapot.ppm -zoom 2} err] $err
- } {1 {unrecognized option "-zoom": must be -format, -from, -shrink, or -to}}
- test imgPhoto-4.32 {ImgPhotoCmd procedure: read option} {
- list [catch {p1 read bogus} err] [string tolower $err]
- } {1 {couldn't read image file "bogus": no such file or directory}}
- test imgPhoto-4.33 {ImgPhotoCmd procedure: read option} {
- list [catch {p1 read $tk_library/demos/images/teapot.ppm \
- -format bogus} err] $err
- } {1 {image file format "bogus" is unknown}}
- test imgPhoto-4.34 {ImgPhotoCmd procedure: read option} {
- list [catch {p1 read README} err] $err
- } {1 {couldn't recognize data in image file "README"}}
- test imgPhoto-4.35 {ImgPhotoCmd procedure: read option} {
- p1 read $tk_library/demos/images/teapot.ppm -shrink
- list [image width p1] [image height p1] [p1 get 120 120]
- } {256 256 {161 109 82}}
- test imgPhoto-4.36 {ImgPhotoCmd procedure: read option} {
- p1 read $tk_library/demos/images/teapot.ppm -from 0 70 60 120 \
- -to 10 10 -shrink
- list [image width p1] [image height p1] [p1 get 29 19]
- } {70 60 {244 180 144}}
- test imgPhoto-4.37 {ImgPhotoCmd procedure: redither option} {
- p1 redither
- list [catch {p1 redither x} err] $err
- } {1 {wrong # args: should be "p1 redither"}}
- test imgPhoto-4.38 {ImgPhotoCmd procedure: write option} {
- list [catch {p1 write} err] $err
- } {1 {wrong # args: should be "p1 write fileName ?-format format-name??-from x1 y1 x2 y2?"}}
- test imgPhoto-4.39 {ImgPhotoCmd procedure: write option} {
- list [catch {p1 write teapot.tmp -format bogus} err] $err
- } {1 {image file format "bogus" is unknown}}
-
- test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} {
- eval image delete [image names]
- .c delete all
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- .c create image 0 0 -image p1 -tags p1.1
- .c create image 256 0 -image p1 -tags p1.2
- .c create image 0 256 -image p1 -tags p1.3
- update
- .c delete i1.1
- p1 configure -width 1
- update
- .c delete i1.2
- p1 configure -height 1
- update
- image delete p1
- } {}
-
- test imgPhoto-6.1 {ImgPhotoDisplay procedure, blank display} {
- .c delete all
- image create photo p1 -width 10 -height 10
- p1 blank
- .c create image 10 10 -image p1
- update
- } {}
-
- test imgPhoto-7.1 {ImgPhotoFree procedure, resource freeing} {
- eval image delete [image names]
- .c delete all
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- .c create image 0 0 -image p1 -anchor nw
- update
- .c delete all
- image delete p1
- } {}
- test imgPhoto-7.2 {ImgPhotoFree procedures, unlinking} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- .c create image 10 10 -image p1 -anchor nw
- button .b1 -image p1
- button .b2 -image p1
- button .b3 -image p1
- pack .b1 .b2 .b3
- update
- destroy .b2
- update
- destroy .b3
- update
- destroy .b1
- update
- .c delete all
- } {}
- test imgPhoto-7.3 {ImgPhotoFree procedures, multiple visuals} {
- image create photo p1 -file $tk_library/demos/images/teapot.ppm
- button .b1 -image p1
- frame .f -visual best
- button .f.b2 -image p1
- pack .f.b2
- pack .b1 .f
- update
- destroy .b1
- update
- .f.b2 configure -image {}
- update
- destroy .f
- image delete p1
- } {}
-
- test imgPhoto-8.1 {ImgPhotoDelete procedure} {
- image create photo p2 -file $tk_library/demos/images/teapot.ppm
- image delete p2
- } {}
- test imagePhoto-8.2 {ImgPhotoDelete procedure} {
- image create photo p2 -file $tk_library/demos/images/teapot.ppm
- rename p2 newp2
- set x [list [info command p2] [info command new*] [newp2 cget -file]]
- image delete p2
- lappend x [info command new*]
- } "{} newp2 $tk_library/demos/images/teapot.ppm {}"
-
- test imagePhoto-9.1 {ImgPhotoCmdDeletedProc procedure} {
- image create photo p2 -file $tk_library/demos/images/teapot.ppm
- rename p2 {}
- list [lsearch -exact [image names] p2] [catch {p2 foo} msg] $msg
- } {-1 1 {invalid command name "p2"}}
-
- destroy .c
- eval image delete [image names]
-